package com.supreme.nettyapp.generalclient.pingclient.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.mqtt.MqttMessage;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class PingClientHandler extends SimpleChannelInboundHandler<MqttMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, MqttMessage mqttMessage) throws Exception {
        switch (mqttMessage.fixedHeader().messageType()) {
            case PINGRESP:
                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                LocalDateTime localDateTime = LocalDateTime.now();
                String datetime = localDateTime.format(dateTimeFormatter);
                System.out.println(datetime + " 收到服务端应答");
                break;
        }
    }
}
